<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>课程管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/layui.css" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script th:inline="none">
        layui.use(["layer","table"],function (){
            var layer=layui.layer;
            var table=layui.table;
            table.render({
                elem:"#schedules",
                url:"scheduleslists",
                page:true,
                toolbar:'#toolbarDemo',
                limit:5,
                cols: [[ //表头
                    {field: 'id', title: '编号', width:100, sort: true}
                    ,{field: 'lname', title: '课程名称', width:180}
                    ,{field: 'cname', title: '班级名称', width:180}
                    ,{field: 'starttime', title: '开始时间', width:180,templet:"<div>{{layui.util.toDateString(d.starttime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                    ,{field: 'endtime', title: '结束时间', width:180,templet:"<div>{{layui.util.toDateString(d.endtime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                    ,{title:"操作",width: 200,toolbar:"#barDemo"}
                ]]

            })
            table.on('toolbar(schedulestab)',function (obj){
                if(obj.event=="add"){
                    layer.open({
                        type:2,
                        title:"添加排课",
                        area:["650px","500px"],
                        content:"toaddschedule"
                    })
                }
            })
            table.on('tool(schedulestab)',function (obj){
                if(obj.event=="update"){
                    layer.open({
                        type:2,
                        title:"修改排课",
                        area:["650px","500px"],
                        content:"toupdateschedule?id="+obj.data.id,
                    })
                }else if(obj.event=="delete"){
                    layer.confirm('您确定要删除该数据吗？', {
                        btn: ['确定', '取消']
                    }, function(index, layero){
                        $.ajax({
                            url:"deleteschedule",
                            data:{"id":obj.data.id},
                            type:"post",
                            dataType:"json",
                            success:function(dataJson){
                                if(dataJson.code==200){
                                    location.reload();
                                }else{
                                    layer.msg(dataJson.msg);
                                }
                            }
                        })
                    }, function(index){

                    })
                }
            })


        })
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        </div>

    </script>
    <script type="text/html" id="barDemo">

        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update">修改</button>
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</button>
    </script>
    </script>
</head>
<body>
<table id="schedules" lay-filter="schedulestab"></table>
</body>
</html>
